<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>年分销商比例管理</title>
	<meta name="decorator" content="ani"/>
	<script type="text/javascript">

		$(document).ready(function() {
			$("#inputForm").validate({
				submitHandler: function(form){
					jp.loading();
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
			  //监听代理商选择事件
            $("#agents").change(function(){
            	var $this = $(this);
				var agentId = $("#agents").val();
				jp.loading();
		        jp.get("${ctx}/web/wxAgents/equipments/" + agentId, function (data) {
	            	appendToSelect($("#equipment"), data);
	            	$("#parentAgentForm").show();
	            	jp.success('查询成功');
		        })
            });

			//代理商设备信息追加到下拉框
            function appendToSelect($select,data){
            	$select.html('');//清空
            	var htmlStr = '';
            	if(data == null || data.length == 0){
            		$select.html('<option value="-1">暂无可选数据</option>');
            		return;
            	}

          
            	//拼接信息
            	//代理商设备下拉列表
            	$.each(data, function(index, obj){
            		htmlStr += '<option value="' + obj.equipment.id + '">' + obj.equipment.userName '</option>';
            	});
				//添加到select下
            	$select.html(htmlStr);
            }
		});
	</script>
</head>
<body>
<div class="wrapper wrapper-content">				
<div class="row">
	<div class="col-md-12">
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h3 class="panel-title"> 
				<a class="panelButton" href="${ctx}/web/yjAgentsDistribution"><i class="ti-angle-left"></i> 返回</a>
			</h3>
		</div>
		<div class="panel-body">
		<form:form id="inputForm" modelAttribute="yjAgentsDistribution" action="${ctx}/web/yjAgentsDistribution/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>	
				<div class="form-group">
					<label class="col-sm-2 control-label">备注信息：</label>
					<div class="col-sm-10">
						<form:textarea path="remarks" htmlEscape="false" rows="4"    class="form-control "/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">分销商：</label>
					<div class="col-sm-10">
						<sys:gridselect url="${ctx}/web/wxAgents/data" id="agents" name="agents.id" value="${yjAgentsDistribution.agents.id}" labelName="agents.userName" labelValue="${yjAgentsDistribution.agents.userName}"
							 title="选择分销商" cssClass="form-control required" fieldLabels="id|昵称" fieldKeys="id|userName" searchLabels="id|昵称" searchKeys="id|userName" ></sys:gridselect>
					</div>
				</div>
				
				<div class="form-group" id="parentAgentForm" style="display:none;">
					<label class="col-sm-2 control-label"><font color="red">*</font>代理商设备号：</label>
					<div class="col-sm-4">
						<%-- <form:select path="parentId" items="${list}" itemLabel="userName" cssClass="form-control"
									 itemValue="id"></form:select> --%>

									<select id="equipment" name="equipment" class="form-control" >
										<!-- <option value="1">13420902166</option>
										<option value="2">13420902177</option> -->
									</select>
								</div>
				</div>
				
				<div class="form-group">
					<label class="col-sm-2 control-label">一年后比例(百分比 如百分之1则=1 不设定则=0)：</label>
					<div class="col-sm-10">
						<form:input path="agentsDistributionA" htmlEscape="false"    class="form-control  isIntGteZero required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">二年后比例(百分比 如百分之1则=1 不设定则=0)：</label>
					<div class="col-sm-10">
						<form:input path="agentsDistributionB" htmlEscape="false"    class="form-control  isIntGteZero required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">三年后比例(百分比 如百分之1则=1 不设定则=0)：</label>
					<div class="col-sm-10">
						<form:input path="agentsDistributionC" htmlEscape="false"    class="form-control  isIntGteZero required"/>
					</div>
				</div>
 				<div class="col-lg-3"></div>
		        <div class="col-lg-6">
		             <div class="form-group text-center">
		                 <div>
		                     <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
		                 </div>
		             </div>
		        </div>
 		</form:form>
		</div>				
	</div>
	</div>
</div>
</div>
</body>
</html>